package com.fr.report.script.function;

import com.fr.report.script.Function;
import com.fr.report.script.Function.Type;
import com.fr.report.script.NormalFunction;
import com.fr.report.script.core.FArray;
import com.fr.report.script.core.FunctionHelper;

public class PRODUCT extends NormalFunction
{
  public Object run(Object[] paramArrayOfObject)
  {
    double d = 1.0D;
    for (int i = 0; i < paramArrayOfObject.length; ++i)
    {
      if (paramArrayOfObject[i] == null)
        break label33:
      d *= parseProductObject(paramArrayOfObject[i]);
    }
    label33: return FunctionHelper.parsePrimitiveDouble(d);
  }

  private double parseProductObject(Object paramObject)
  {
    if (paramObject instanceof Number)
      return ((Number)paramObject).doubleValue();
    if (paramObject instanceof Boolean)
      return ((((Boolean)paramObject).booleanValue()) ? 1.0D : 0.0D);
    if (paramObject instanceof FArray)
    {
      FArray localFArray = (FArray)paramObject;
      double d = 1.0D;
      int i = 0;
      int j = localFArray.length();
      while (i < j)
      {
        d *= parseProductObject(localFArray.elementAt(i));
        ++i;
      }
      return d;
    }
    try
    {
      return Double.parseDouble(paramObject.toString());
    }
    catch (NumberFormatException localNumberFormatException)
    {
    }
    return 1.0D;
  }

  public Function.Type getType()
  {
    return Function.MATH;
  }

  public String getCN()
  {
    return "PRODUCT(number1,number2, ...):将所有以参数形式给出的数字相乘，并返回乘积值。\nnumber1, number2, ...:为 1 到 30 个需要相乘的数字参数。\n示例:\nPRODUCT(3,4) 等于 12\nPRODUCT(3,4,5) 等于 60\n\n";
  }

  public String getEN()
  {
    return "PRODUCT(number1,number2, ...): Multiplies all the numbers given as arguments and returns the product.\nNumber1, number2, ... are 1 to 30 numbers that you want to multiply.\n\nExample:\n   PRODUCT(3,4) = 12\n   PRODUCT(3,4,5) = 60\n\n";
  }
}